package sword.T62;

/**
 * @Author: 18362
 * @Create: 2022-04-10 16:26:56 星期日
 */
class Solution {
    public int lastRemaining(int n, int m) {
        int res = 0;
        for (int i=2; i<=n; ++i) {
            res = (res + m) % i;
        }
        return res;
    }
}